<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<%@ taglib uri="http://www.ufida.com/uif" prefix="uif" %> 
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<html>
	<head>
		<lfw:base/>
		<lfw:import/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<script type='text/javascript' src='code/webbxmainquery'></script>
		<script>
			function afterPageInit() 
			{
		 		var ds = getDataset('webbx_main_query_ds');
		 		ds.setRowSelected(0);
			}
		</script>
	</head>
	<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" scroll=no onload="pageBodyScript()" style="background-color:transparent">
		<lfw:pageModel className="nc.lfw.finance.main.WebBxMainPageQueryPageModel">
			<lfw:layout type="border" border="0">
				<lfw:layoutPanel position="center">
					<lfw:form id="webbx_main_query_form"></lfw:form>
				</lfw:layoutPanel>
				<lfw:layoutPanel align="center" position="bottom" height="34">
					<lfw:button id="quickQueryBtn"></lfw:button>
				</lfw:layoutPanel>
			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>	
<script language="javascript">
	function externalInit()
	{   
	}
	
	function doQuickQuery()
	{  
		var sql = getQuickQuerySql();
		$query(sql);
	}
	
	function $query(sql)
	{
		var queryParamArray = '';
		log("quick query condition sql: " + sql);
		var dsId = '<%=request.getParameter("dsId")%>';
		var targetDs = parent.getDataset(dsId);
		targetDs.reqParameterMap.clear();
		targetDs.addReqParameter('WEBBX_MAIN_QUERY', sql);
		targetDs.addReqParameter('WEBBX_MAIN_ADVANCED_QUERY_FLAG','Y');
		targetDs.addReqParameter(IDatasetConstant.FROM_QUERY_TEMPLATE, "false");
		var args = [targetDs];
		
		if(dsId == "myDjDs")
			parent.showLoadingDataDiv(parent.getComponent("myDjGrid").outerDiv);
		else if(dsId == "myJobDs")
			parent.showLoadingDataDiv(parent.getComponent("myJobGrid").outerDiv);
		
		var loader = new DatasetLoader(targetDs);
		loader.setKeyValue(Dataset.MASTER_KEY);
		loader.setReturnFunc($qryReturnFunc);
		loader.setReturnArgs(args);
		loader.load(parent);
	}
	
	function getQuickQuerySql()
	{
		var ds = getDataset("webbx_main_query_ds");
		var row = ds.getSelectedRow();
		var sql = ''; 
		if(row != null){
			for(var i=0; i < row.getSize(); i++){
				var field = ds.metadata[i].key;
				var value = row.getCellValue(i);
				if(value == null || value == '' || value == "-11111")
					continue;
					
				if(sql != '')
					sql += ' and ';
				if(field == 'spzt' && value == '-10000')//暂存
					sql += 'a.djzt=0'	
				else
					sql += 'a.' + field + '=' + "'" + value + "'"
			}			
		}
		if(sql == '') 
			sql = '1=1';
		return sql;
	}
	
	function $qryReturnFunc(args, isSuccess) {
		if(isSuccess){
			var ds = args[0];
			if(ds.getRowCount() > 0 && ds.getSelectedIndex() == -1)
				ds.setRowSelected(0);
		}
		parent.hideDialog("quickquery_dialog", true);
	}
	
	function getMainFrame() {
		return parent.mainFrame;
	}
</script>
